import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { AdvertForm, AdvertPageResult, AdvertQuery } from "./types";

/* 获取广告分页列表 */
export function listAdvertPages(
  queryParams: AdvertQuery
): AxiosPromise<AdvertPageResult> {
  return request({
    url: "/mall-sms/api/v1/adverts/pages",
    method: "get",
    params: queryParams,
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 获取广告详情 */
export function getAdvertForm(id: number): AxiosPromise<AdvertForm> {
  return request({
    url: "/mall-sms/api/v1/adverts/" + id,
    method: "get",
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 添加广告 */
export function addAdvert(data: AdvertForm) {
  return request({
    url: "/mall-sms/api/v1/adverts",
    method: "post",
    data: data,
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 修改广告 */
export function updateAdvert(id: number, data: AdvertForm) {
  return request({
    url: "/mall-sms/api/v1/adverts/" + id,
    method: "put",
    data: data,
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 删除广告 */
export function deleteAdverts(ids: string) {
  return request({
    url: "/mall-sms/api/v1/adverts/" + ids,
    method: "delete",
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}
